home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 2.iso / dist / fw_netpbm.idb / usr / freeware / bin / ppmquantall.z / ppmquantall
Text File  |  2001-01-10  |  2KB  |  58 lines

  1. #!/bin/csh -f
  2. #
  3. # ppmquantall - run ppmquant on a bunch of files all at once, so they share
  4. #               a common colormap
  5. #
  6. # WARNING: overwrites the source files with the results!!!
  7. #
  8. # Verbose explanation: Let's say you've got a dozen pixmaps that you want
  9. # to display on the screen all at the same time.  Your screen can only
  10. # display 256 different colors, but the pixmaps have a total of a thousand
  11. # or so different colors.  For a single pixmap you solve this problem with
  12. # ppmquant; this script solves it for multiple pixmaps.  All it does is
  13. # concatenate them together into one big pixmap, run ppmquant on that, and
  14. # then split it up into little pixmaps again.
  15.  
  16. if ( $#argv < 3 ) then
  17.     echo "usage:  ppmquantall <newcolors> <ppmfile> <ppmfile> ..."
  18.     exit 1
  19. endif
  20.  
  21. set newcolors=$argv[1]
  22. set files=( $argv[2-] )
  23.  
  24. # Extract the width and height of each of the images.
  25. # Here, we make the assumption that the width and height are on the
  26. # second line, even though the PPM format doesn't require that.
  27. # To be robust, we need to use Pnmfile to get that information, or 
  28. # Put this program in C and use ppm_readppminit().
  29.  
  30. set widths=()
  31. set heights=()
  32. foreach i ( $files )
  33.     set widths=( $widths `head -2 $i | tail -1 | sed 's/ .*//'` )
  34.     set heights=( $heights `head -2 $i | tail -1 | sed 's/.* //'` )
  35. end
  36.  
  37. set all=/tmp/pqa.all.$$
  38. rm -f $all
  39. pnmcat -topbottom -jleft -white $files | ppmquant -quiet $newcolors > $all
  40. if ( $status != 0 ) exit $status
  41.  
  42. @ y = 0
  43. @ i = 1
  44. while ( $i <= $#files )
  45.     pnmcut -left 0 -top $y -width $widths[$i] -height $heights[$i] $all \
  46.        > $files[$i]
  47.     if ( $status != 0 ) exit $status
  48.     @ y = $y + $heights[$i]
  49.     @ i++
  50. end
  51.  
  52. rm -f $all
  53.  
  54.  
  55.  
  56.  
  57.  
  58.